<template>
	<div class="cellpage systemPage-wrapper">
		<div class="topbar">
			<span class="iconfont iconxitongpingtai-biaodanguanli titleIcon "></span>
			<span>表单管理</span>
		</div>
		<div class="content-background divcontent">
			<!-- 左侧表单名称列表 -->
			<pageMenu :selectShow="true" :menuitems="menuitems" :selectName="selectName" @menuitemss="menuitemss"
				@microIdss="microIdss" @itemclick="itemclick" @add="add" :activeitem="activeitem" :dropmenus="dropmenus"
				@dropitemclick="dropitemclick" @search="searchCell"></pageMenu>
			<div class="page-cell-edit">
				<!-- 右侧表单组件 -->
				<sysCell ref="cell" :cellid="cellid"></sysCell>
			</div>
		</div>

		<winAdd v-if="showWind" @close="closeWind" @ok="save" :title="addtitle" :activeItem="repClass"></winAdd>
	</div>
</template>

<script>
	import pageMenu from '../components/pageMenu.vue'
	import sysCell from '../components/sysCell.vue'
	import winAdd from '../components/winAdd.vue'
	import { repClassquery, repClasssave, repClassdetail, repClassdelete } from '@/system/api/cellEdit'
	export default {
		name: "cellEdit",
		components: {
			pageMenu, sysCell, winAdd
		},
		provide() {
			return {
				cEdit: this
			}
		},
		data() {
			return {
				repClassParams: {
					name: "",
					microId: 1
				},
				menuitems: [], // 保存当前项或所有项返回信息
				activeitem: 0, // 第几项
				showWind: false, // 控制编辑或删除弹框
				repClass: null,
				report: null,
				dropmenus: [{
					name: '编辑',
					iconPosition: 'before',
					iconname: 'editicon',
					value: 1
				},
				{
					name: '删除',
					iconPosition: 'before',
					iconname: 'delicon',
					value: 2
				}],
				cellid: null, // 当前项id
				addtitle: null,
				selectName: '表单管理',
				microId: ''
			}
		},
		mounted() {
			this.repClassquery();
		},
		methods: {
			itemclick(e, index) {// 点击每一项
								// if(this.$refs.cell.hasChange()){
								// 	this.messageBox('是否保存表单').then((res)=>{
								// 		if(res.type=='confirm'){
								// 			this.$refs.cell.reportsave();
								// 		}
								// 		this.activeitem = index;
								// 		this.cellid = e.id;
								// 	})
								// }else{
				this.$refs.cell.clearCom();
				this.activeitem = index;
				this.cellid = e.id; // 发请求
								// }


			},
			add() {
				//				this.message('new',1);
				this.repClass = null;
				this.showWind = true;
				this.addtitle = "新增表单类"
				this.activeitem = -1;
			},
			dropitemclick(item, dropItem, index) {

				if (dropItem.name == "编辑") {
					this.addtitle = "编辑表单类"
					this.repClass = item;
					this.showWind = true;
				}
				if (dropItem.name == "删除") {
					let param = { id: item.id }
					repClassdelete(param).then((res) => {
						if (res.success) {
							this.activeitem = 0;
							this.repClassquery();
							this.message(res.msg, 1);
						} else {
							this.message(res.msg, 3)
						}
					})
				}
			},
			searchCell(e) {
				this.repClassParams.name = e;
				this.repClassParams.microId = this.microId
				this.repClassquery();
			},
			closeWind() {
				this.showWind = false;
				console.log(this.showWind);
			},
			// 新增？？
			save(resinfo) {
				this.showWind = false;
				this.repClass = resinfo;
				repClasssave(this.repClass).then((res) => {
					if (res.success) {
						repClassquery(this.repClassParams).then((rs) => {
							if (rs.success) {
								this.menuitems = rs.info;
								this.activeitem = this.getIndex(res.info);
							}
						});

					} else {
						this.message(res.msg, 3);
					}
				});
			},
			repClassquery() {
				repClassquery(this.repClassParams).then((res) => {
					if (res.success) {
						this.menuitems = res.info;
					}
				});
			},
			getIndex(id) {
				let ind = 0;
				this.menuitems.forEach((item, index) => {
					if (item.id == id) {
						ind = index;
					}
				});
				return ind;
			},
			menuitemss(tablelist) {
				this.menuitems = tablelist
			},
			microIdss(a) {
				this.microId = a;
				this.repClassParams.microId=this.microId;

			}
		}
	}
</script>

<style scoped>
	.cellpage {
		width: 100%;
		height: calc(100% - 55px);
	}

	.titleIcon {
		font-size: 24px;
		margin: 0px 14px 0px 20px;
		color: rgba(83, 168, 255, 1);
	}

	.title {
		width: 72px;
		height: 19px;
		font-size: 18px;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: rgba(0, 0, 0, 1);
		line-height: 21px;
		margin: 19px 0 18px 0px;
	}

	.divcontent {
		display: flex;
		/*height: calc(100% - 56px);
		width: 100%;
    	padding: 12px;
    	border-radius: 6px;*/
	}

	.page-cell-edit {
		margin-left: 12px;
		width: calc(100% - 246px);
		max-width: calc(100% - 246px);
	}

	.page-cell ::-webkit-scrollbar {
		height: 3px;
		width: 3px;
	}
</style>